<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        编写函数norepeat(arr) 将数组的重复元素去掉，并返回新的数组<br>

            var arr = [1, 1, 2, 3, 4, 4, 2, 1, 3, 5]<br>

            function norepeat() {<br>
            // code in here ...<br>
            }

            console.log(norepeat(arr)) // [1, 2, 3, 4, 5]<br>
    </div>
    <script>
        // 利用数组indexOf返还值降重
        function noRepeat1 ( arr ) {
            var arr2 = new Array () ;
            for ( var i = 0 ; i < arr.length ; i ++ ) {
                if ( arr2.indexOf(arr[i]) == -1 )
                {
                    arr2.push(arr[i]);
                }
            }
            return arr2 ; 
        }
        // 利用对象键名不重复降重 
        function noRepeat2 ( arr ) {
            var obj = {} ;
            var arr2 = new Array();
            for ( var i = 0 ; i < arr.length ; i ++ ) {
                obj[arr[i]] = arr[i] ; 
            }
            for ( var key in obj ) {
                arr2.push(obj[key]);
            }
            return arr2 ;
        }
        // 利用集合元素不重复方法降重
        function noRepeat3 ( arr ) {
            var set = new Set(arr);
            var arr2 = Array.from(set);
            return arr2 ;
        }
        var arr = [1,5,4,7,6,9,5,1,4,5,2,7,6];
        console.log(noRepeat1(arr));
        console.log(noRepeat2(arr));
        console.log(noRepeat3(arr));
    </script>
</body>
</html>